package ai.people.netmon.framework.utils;

import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.exception.enums.ExceptionEnum;
import ai.people.netmon.framework.exception.type.CustomizeRuntimeException;
import ai.people.netmon.framework.model.response.Result;

import java.io.Serializable;


/**
 * 响应工具类
 *
 * @author yuanqinglong
 * @date 2022/1/7 10:56
 */
public class ResultUtil implements Serializable {


    /**
     * 查询操作成功
     *
     * @return {@link Result}
     */
    public static <T> Result<T> success() {
        return success(null);
    }

    /**
     * 查询操作成功
     *
     * @param object 返回的结果数据
     * @return {@link Result}
     */
    public static <T> Result<T> success(Object object) {
        return new Result<>(object);
    }

    /**
     * 错误
     *
     * @return {@link Result}<{@link T}>
     */
    public static <T>Result<T> error() {
        return new Result<>(CommonEnum.FAIL);
    }

    /**
     * 错误
     *
     * @param exception 异常
     * @return {@link Result}<{@link T}>
     */
    public static <T>Result<T> error(ExceptionEnum exception) {
        return new Result<>(exception);
    }

    /**
     * 错误
     *
     * @param exception 异常
     * @return {@link Result}<{@link T}>
     */
    public static <T>Result<T> error(CustomizeRuntimeException exception) {
        return new Result<>(exception);
    }

    /**
     * 错误
     *
     * @param code    代码
     * @param message 消息
     * @return {@link Result}<{@link T}>
     */
    public static <T>Result<T> error(int code, String message) {
        return new Result<>(code, message,false);
    }



}
